﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Infragistics.Controls.Schedules;

namespace StartupSolution.Views.Schedules
{
    public partial class ScheduleCodeBehind : Page
    {
        public ScheduleCodeBehind()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(ScheduleCodeBehind_Loaded);
        }

        void ScheduleCodeBehind_Loaded(object sender, RoutedEventArgs e)
        {
            // Create a ListScheduleDataConnector to connect the schedule data source to the XamScheduleDataManager.
            ListScheduleDataConnector dataConnector = new ListScheduleDataConnector();

            dataConnector.ResourceItemsSource = SchedulesData.Resources;
            dataConnector.ResourceCalendarItemsSource = SchedulesData.Calendars;
            dataConnector.AppointmentItemsSource = SchedulesData.Appointments;

            // Create a XamScheduleDataManager object and set its DataConnector property.
            XamScheduleDataManager dataManager = new XamScheduleDataManager();
            dataManager.DataConnector = dataConnector;

            // Create a CalendarGroupCollection object to add CalendarGroup objects.
            CalendarGroupCollection calendarGroupCollection = dataManager.CalendarGroups;
            CalendarGroup calendarGroup = new CalendarGroup();
            calendarGroup.InitialCalendarIds = "[resource1[calendar1]]";
            calendarGroupCollection.Add(calendarGroup);

            // Use one of the schedule views - day view, month view or scheduleView.
            // Create a XamDayView.
            XamDayView view = new XamDayView();

            // You can change the view to month view.
            // TODO: Create a XamMonthView.
            // XamMonthView view = new XamMonthView();

            // Or
            // TODO: Create a XamScheduleView.
            // XamScheduleView view = new XamScheduleView();

            view.Width = 700;
            view.Height = 500;
            view.VerticalAlignment = System.Windows.VerticalAlignment.Top;

            // Set the view property DataManager
            view.DataManager = dataManager;

            // Add the schedule control to the LayoutRoot container.
            LayoutRoot.Children.Add(view);

            // Position the control in the second grid row
            Grid.SetRow(view, 2);
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

    }
}
